# -*- coding: utf-8 -*-

import os
import sys
import logging
from logging import handlers

import config


def get_r_squared(y_true, y_test) -> float:
    """
    计算拟合度
    :param y_true: 真实值
    :param y_test: 测试值
    :return:
    """
    numerator = ((y_test - y_true) ** 2).sum()  # 分子
    denominator = ((y_true - y_true.mean()) ** 2).sum()  # 分母
    r_squared = 0
    if denominator != 0:
        r_squared = 1.0 - float(numerator / denominator)
        pass
    return r_squared


def create_folder(path):
    """判断文件路径或文件夹是否存在，不存在就创建"""
    if not os.path.exists(path):
        index = path.rfind(os.sep)
        if index == -1:
            folder = path
        else:
            folder = path[:index]
            pass
        if not os.path.exists(folder):
            os.makedirs(folder)
            pass
        pass
    pass


if __name__ == '__main__':
    pass
